package com.tsing.bms.controller;

import com.tsing.bms.service.IUnitService;
import com.tsing.bms.vo.req.IdReqVo;
import com.tsing.bms.vo.req.IdsReqVo;
import com.tsing.bms.vo.req.UnitAddReqVo;
import com.tsing.bms.vo.req.UnitUpdateReqVo;
import com.tsing.bms.vo.resp.UnitRespVo;
import com.tsing.common.annotations.SystemLog;
import com.tsing.common.utils.ResultUtil;
import com.tsing.common.vo.ResultData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author TheTsing
 * @since 2021-03-29
 */
@Api(tags = "单元管理")
@RestController
@RequestMapping("/unit")
public class UnitController {

    @Autowired
    private IUnitService unitService;

    @PostMapping("/addUnit")
    @ApiOperation(value = "新增单元")
    @SystemLog(description = "新增单元")
    public ResultData addUnit(@Validated @RequestBody UnitAddReqVo reqVo) {
        unitService.addUnit(reqVo);
        return ResultUtil.success();
    }

    @DeleteMapping("/deleteUnit")
    @ApiOperation(value = "删除单元")
    @SystemLog(description = "删除单元")
    public ResultData deleteUnit(@Validated @RequestBody IdsReqVo reqVo) {
        unitService.deleteUnit(reqVo);
        return ResultUtil.success();
    }

    @GetMapping("/getUnit")
    @ApiOperation(value = "获取单个单元信息")
    @SystemLog(description = "获取单个单元信息")
    public ResultData<UnitRespVo> getUnitById(@Validated IdReqVo reqVo) {
        return ResultUtil.success(unitService.getUnitById(reqVo));
    }

    @PutMapping("/updateUnit")
    @ApiOperation(value = "修改单元信息")
    @SystemLog(description = "修改单元信息")
    public ResultData updateUnit(@Validated @RequestBody UnitUpdateReqVo reqVo) {
        unitService.updateUnit(reqVo);
        return ResultUtil.success();
    }

    @GetMapping("/unitList")
    @ApiOperation(value = "单元列表")
    @SystemLog(description = "单元列表")
    public ResultData<List<UnitRespVo>> unitList() {
        return ResultUtil.success(unitService.unitList());
    }

}
